package com.zb.lister;

import com.alibaba.fastjson.JSON;
import com.zb.config.RabbitConfig;
import com.zb.entity.Exchangescore;
import com.zb.entity.Shipments;
import com.zb.service.ExchangescoreService;
import com.zb.service.ShipmentsService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ListerProduct {

    @Autowired
    private ShipmentsService shipmentsService;

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private ExchangescoreService exchangescoreService;

    @RabbitListener(queues = RabbitConfig.SCORE_ONE_QUEUE)
    public void create(String json) throws Exception{
        Exchangescore exchange = JSON.parseObject(json, Exchangescore.class);
        if(exchange!=null){
            Integer flag = exchangescoreService.qdtxDeleteExchangescoreById(exchange.getId());
            if(flag>0){
                Shipments shipments = new Shipments();
                shipments.setProductId(exchange.getProductId());
                shipments.setType(2);
                shipments.setCreditExchangeId(exchange.getId());
                shipmentsService.qdtxAddShipments(shipments);
                rabbitTemplate.convertAndSend(RabbitConfig.SCORE_TWO_EXCHAGE,RabbitConfig.SCORE_TWO_ROUTING,json);
            }
        }
        System.out.println("删除兑换记录表记录!");
    }
}
